package com.yykj.drup.server.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yykj.drup.server.mapper.ExpressContextDao;
import com.yykj.drup.server.model.ExpressContext;
import com.yykj.drup.server.service.ExpressContextService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zengg
 * @since 2022-03-31
 */
@Service
public class ExpressContextServiceImp extends ServiceImpl<ExpressContextDao, ExpressContext> implements ExpressContextService {


    @Override
    public List<ExpressContext> findContextsByOrderComNumber(String orderComNumber) {
        LambdaQueryWrapper<ExpressContext> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ExpressContext::getOrderComNumber,orderComNumber)
                .orderByDesc(ExpressContext::getFtime);
        return this.list(wrapper);
    }

    @Override
    public void insertExpressContext(List<ExpressContext> expressContexts) {
        expressContexts.stream().forEach(expressContext -> {
            if (this.findByOrderComNumber(expressContext.getOrderComNumber(),expressContext.getFtime()) == null){
                this.save(expressContext);
            }
        });
    }

    @Override
    public ExpressContext findByOrderComNumber(String orderComNumber, String ftime) {
        LambdaQueryWrapper<ExpressContext> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ExpressContext::getOrderComNumber,orderComNumber)
                .eq(ExpressContext::getFtime,ftime);
        return this.getOne(wrapper);
    }
}
